package com.pactera.utils;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.Map;

public class Assert {

    private Assert() {
    }

    public static void isFalse(boolean expression, String message) {
        if (expression) {
            throw new AssertException(message);
        }
    }

    public static void isTrue(boolean expression, String message) {
        isFalse(!expression, message);
    }

    public static void isNotNull(Object object, String message) {
        isFalse(object == null, message);
    }

    public static void isNull(Object object, String message) {
        isFalse(object != null, message);
    }

    public static void isNotBlank(String text, String message) {
        isFalse(StringUtils.isBlank(text), message);
    }

    public static void isBlank(String text, String message) {
        isFalse(StringUtils.isNotBlank(text), message);
    }

    public static void isNotContains(String text, String search, String message) {
        isFalse(StringUtils.contains(text, search), message);
    }

    public static void isContains(String text, String search, String message) {
        isFalse(!StringUtils.contains(text, search), message);
    }

    public static void startWith(String text, String prefix, String message) {
        isFalse(!StringUtils.startsWith(text, prefix), message);
    }

    public static void startNotWith(String text, String prefix, String message) {
        isFalse(StringUtils.startsWith(text, prefix), message);
    }

    public static void endWith(String text, String prefix, String message) {
        isFalse(!StringUtils.endsWith(text, prefix), message);
    }

    public static void endNotWith(String text, String prefix, String message) {
        isFalse(StringUtils.endsWith(text, prefix), message);
    }

    public static void isNotEmpty(Object[] array, String message) {
        isFalse(ArrayUtils.isEmpty(array), message);
    }

    public static void isEmpty(Object[] array, String message) {
        isFalse(ArrayUtils.isNotEmpty(array), message);
    }

    public static void isNotEmpty(Collection<?> collection, String message) {
        isFalse(CollectionUtils.isEmpty(collection), message);
    }

    public static void isEmpty(Collection<?> collection, String message) {
        isFalse(CollectionUtils.isNotEmpty(collection), message);
    }

    public static void isNotEmpty(Map<?, ?> map, String message) {
        isFalse(MapUtils.isEmpty(map), message);
    }

    public static void isEmpty(Map<?, ?> map, String message) {
        isFalse(MapUtils.isNotEmpty(map), message);
    }
}
